home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-06 / charon40.zip / CALLBACK.H < prev    next >
C/C++ Source or Header  |  1992-03-26  |  4KB  |  131 lines

  1. /* callback.h - define callback functions for loadable modules */
  2. #ifndef    _CALLBACK_H
  3. #define    _CALLBACK_H
  4.  
  5. /*
  6.     A loadable module is a 'C' source program which has been
  7.     compiled under BC or TC using tiny model with -r save regs.
  8.  
  9.         bcc -mt -r source.c
  10.         link source.obj,source.exe,source.map, cs.lib
  11.         rem note that c0t.obj is NOT linked in
  12.         exe2bin source.exe source.bin
  13.  
  14.         copy source.bin sys:usr\charon\spool
  15.  
  16.     Tiny model programs have only one segment, DS=CS=SS
  17.  
  18.     The data segment is composed of static initialized data
  19.     and unititialized data (BSS).
  20.  
  21.     Charon runs multiple copies of the module by generating a unique
  22.     data/stack area, and using a shared code segment.
  23.  
  24.     Each instance of the module has its own stack and BSS data, but
  25.     shares the static data.
  26.  
  27.     Therefore, if you intend to keep 'local' data that persists between
  28.     callbacks, you must store it a) on the stack, or b) in unitialized
  29.     data.
  30.  
  31.     The module's context is switched during every callback (ala windows).
  32.  
  33.     If you want to share a writable variable between all instances, be sure
  34.     that it is not located within the last paragraph of the static data
  35.     segment, as the BSS area is rounded down to the previous paragraph.
  36.  
  37.     Therefore up to 15 bytes of static data may not actually be common
  38.     between instances. This amount is called the `Pump Size' and can
  39.     be determined using the Object Information Display of Charon.
  40.  
  41.     This .h file provides the defines and mechanisms to allow the
  42.     module creator to test the module as a stand-alone program, conversion
  43.     to a module involves recompiling with a #define set.
  44.  
  45.  
  46.  
  47.     Callbacks are achieved by defining a few common functions that
  48.     provide I/O for the module.
  49.  
  50.     The '_start' procedure must be the first procedure defined
  51.     in the executable file. You may have other procedures, but they
  52.     must be defined after _start.
  53.  
  54.     the definition for _start is
  55.  
  56.         int _start(argc, char *argv[], struct NXlate far *callptr)
  57.  
  58.     where callptr is a far ptr to a data item that must be returned
  59.     in all callbacks.
  60.  
  61.  
  62.     The callback.c module includes a definition for _start which
  63.     calls a main(int argc, char *argv[]) function...
  64.  
  65.     Before including this module, you must #define a setting to
  66.     indicate if the program will be a module, or standalone.
  67.  
  68.     #define    STANDALONE    0         compile as module
  69.     #define    STANDALONE    1        compile as standalone program
  70. */
  71.  
  72. #define    STDIN    0
  73. #define    STDOUT    1
  74. #define    STDERR    2
  75.  
  76. #define    CB_READ        0
  77. #define    CB_WRITE    1
  78. #define    CB_GETENV    2
  79. #define    CB_SETENV    3
  80. #define    CB_TELLP    4
  81. #define    CB_SEEKP    5
  82. #define    CB_MAXCALLS    5
  83.  
  84. /* define valid return codes, OR them together optional returncode in lower byte */
  85. #define    RT_CHANGED_TEXT    0x4000    /* the output file was updated */
  86. #define    RT_CHANGED_TAGS    0x2000    /* the file attribute tags were changed */
  87. #define    RT_FAILED    0x1000    /* I couldn't translate this file */
  88. #define    RT_OK        0x0800    /* I did what I could and I finished ok */
  89.  
  90.  
  91. #define    MAX_STRING    256
  92.  
  93. #ifndef    MASTER_SOURCE
  94.  
  95. #ifndef    STANDALONE
  96. #error You must define the STANDALONE def
  97. #endif
  98. #if    !defined(__TINY__)
  99. #error You must compile in the tiny model only
  100. #endif
  101. #if    defined(__OVERLAY__)
  102. #error    You must not compile with overlays
  103. #endif
  104.  
  105. int    read(int handle, char *buffer, int count); /* returns bytes read */
  106. int    write(int handle, char *buffer, int count); /* returns bytes written */
  107.  
  108. char    *getenv(char *string);
  109.  
  110. #if    STANDALONE
  111. #define    tellp(handle)    lseek(handle,0L,1)
  112. #define setenv(s)       putenv(s)
  113. #else
  114. void    setenv(char *string);
  115. long    tellp(int handle);
  116. #endif
  117.  
  118. long    seekp(int handle, long offset, int whence);
  119.  
  120. int    fprintf(int handle, char *format, ...);
  121.  
  122. #ifndef    SEEK_CUR
  123. #define SEEK_CUR    1
  124. #define SEEK_END    2
  125. #define SEEK_SET    0
  126. #endif
  127.  
  128.  
  129. #endif
  130. #endif
  131.